<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript">
        function fun() {
            var num = document.getElementById("num").value;
            num = num.trim();
            var reg = new RegExp(/^\d{1,13}(\.\d{1,})?$/);
            if (!reg.test(num)) {
                alert("你输入的数据不合法!");
                return;
            }
            var dot = num.indexOf(".")
            var intPart = "";
            var decPart = "";
            if (dot >= 0) {
                intPart = num.substring(0, dot) - 0 + "";
                decPart = (num + "00").substr(dot + 1, 2)
            } else {
                intPart = num - 0 + "";
                decPart = "00";
            }
            var res1 = "";
            for (i = intPart.length; i > 0; i = i - 3) {
                if (i - 3 <= 0) {
                    res1 = intPart.substring(0, i) + res1;
                } else {
                    res1 = "," + intPart.substr(i - 3, 3) + res1;
                }
            }
            document.getElementById("res1").innerHTML = res1 + "." + decPart;
            var res2 = "";
            var unit = new Array("萬", "仟", "佰", "拾", "亿", "仟", "佰", "拾", "萬", "仟", "佰", "拾", "元", "角", "分");
            var chineseNum = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
            var temp = intPart + decPart;
            var j = unit.length - 1;
            for (i = temp.length - 1; i >= 0; i--) {
                res2 = chineseNum[temp[i]] + unit[j] + res2;
                j--;
            }
            document.getElementById("res2").innerHTML = res2;
        }
    </script>
</head>
<body>
请输入金额：<input type="text" id="num"/>
<button onclick="fun()">金额转换</button>
<br/>
银行金额：<span id="res1"></span><br/>
大写金额：<span id="res2"></span><br/>
</body>
</html>
